package com.shrfid.rfidsdk.tag.base;


import com.shrfid.module_base.entity.TagEntity;

import java.util.List;



public abstract class BaseResponseData {

    public static final long EXPIRED_TIME = 10 * 1000;//十秒钟过期时间

    public BaseResponseData() {
        responseTimestamp = System.currentTimeMillis();
    }

    /**
     * 解析数据的时间戳
     */
    private long responseTimestamp;

    /**
     * 滚码
     */
    private byte rollCode;

    /**
     * 响应数据
     */
    private List<TagEntity> data;

    /**
     * 是否解析结束
     */
    private boolean complete;

    public boolean isComplete() {
        return complete;
    }

    public void setComplete(boolean complete) {
        this.complete = complete;
    }

    public long getResponseTimestamp() {
        return responseTimestamp;
    }

    public void setResponseTimestamp(long responseTimestamp) {
        this.responseTimestamp = responseTimestamp;
    }

    public byte getRollCode() {
        return rollCode;
    }

    public void setRollCode(byte rollCode) {
        this.rollCode = rollCode;
    }

    public List<TagEntity> getData() {
        return data;
    }

    public void setData(List<TagEntity> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResponseData{" +
                "responseTimestamp=" + responseTimestamp +
                ", rollCode=" + rollCode +
                ", data=" + data +
                ", complete=" + complete +
                '}';
    }

    /**
     * @return 是否过期
     */
    public boolean expired() {
        long time = System.currentTimeMillis();
        return (time - responseTimestamp) > EXPIRED_TIME;
    }

    public abstract void parseFrame(BaseResponseFrame frame);
}
